package com.FTW.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatOptions;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SAA_LLM_Config {

    private final String DeepSeekModel = "deepseek-v3.1";
    private final String Qwen3Model = "qwen3-max-2025-09-23";

    @Bean(name = "deepseek")
    public ChatModel deepSeekModel() {
        return DashScopeChatModel.builder()
                .dashScopeApi(
                        DashScopeApi.builder().apiKey(System.getenv("AI_DASHSCOPE_API_KEY")).build())
                .defaultOptions(
                        DashScopeChatOptions.builder().withModel(DeepSeekModel).build())
                .build();
    }

    @Bean(name = "qwen3")
    public ChatModel qwen3Model() {
        return DashScopeChatModel.builder()
                .dashScopeApi(
                        DashScopeApi.builder().apiKey(System.getenv("AI_DASHSCOPE_API_KEY")).build())
                .defaultOptions(
                        DashScopeChatOptions.builder().withModel(Qwen3Model).build())
                .build();
    }

    @Bean(name = "deepSeekClient")
    public ChatClient deepSeekClient(
            @Qualifier("deepseek") ChatModel chatModel,
            ToolCallbackProvider tools) {

        return ChatClient.builder(chatModel)
                .defaultToolCallbacks(tools.getToolCallbacks())     //mcp协议，其中可用的tools
                .build();
    }

    @Bean(name = "qwen3Client")
    public ChatClient qwen3Client(@Qualifier("qwen3") ChatModel chatModel) {
        return ChatClient.builder(chatModel).build();
    }
}
